using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SiteManager;
using System.Data.SqlClient;
using System.IO;
using System.Text;

public partial class SearchResultsDent : System.Web.UI.Page
{
    //Create an Object of Manager classs
    Manager mgr = new Manager(true,"ConnectionString");
    protected localFunction obj = new localFunction();
    
    public enum FeaturedDentistType { NonFeatured, Standard, Enhanced, Premium };

    public string tDentistsId = "";
    public string frompage = "";
    public string TravelDis = "";
    public int gridcount = 0;

    int pageNoPre = 1;
    int pageNoEnh = 1;
    int pageNoStd = 1;
    int pageNoNon = 1;

    public string StdDentistsId = "";

    /********************************************Added by Wahaj Khan************************/
    protected string Custom_IIF(object s)
    {
        if (object.ReferenceEquals(s, DBNull.Value))
        {
            return "0";
        }
        else
        {
            return Eval("rating", Convert.ToInt32(s).ToString());
        }
    }

    /********************************************Added by Wahaj Khan************************/

    public string UpdateQueryStringItem(System.Web.HttpRequest httpRequest, string queryStringKey, string newQueryStringValue)
    {
        StringBuilder NewURL = new StringBuilder();
        NewURL.Append(httpRequest.RawUrl);

        if (httpRequest.QueryString[queryStringKey] != null)
        {
            string OrignalSet = String.Format("{0}={1}", queryStringKey, httpRequest.QueryString[queryStringKey]);
            string NewSet = String.Format("{0}={1}", queryStringKey, newQueryStringValue);
            NewURL.Replace(OrignalSet, NewSet);
        }
        else if (httpRequest.QueryString.Count == 0)
        {
            NewURL.AppendFormat("?{0}={1}", queryStringKey, newQueryStringValue);
        }
        else
        {
            NewURL.AppendFormat("&{0}={1}", queryStringKey, newQueryStringValue);
        }
        return NewURL.ToString();
    }


    protected void Page_Load(object sender, EventArgs e)
    {
        Master.OASSpecialty = Session["Speciality"].ToString(); 
        
        bool bFeaDocsFound = false;
        bool bStdFeaDoc = false;
        bool bPreFeaDoc = false;
        bool bEnFeaDoc = false;

        try
        {
            pageNoPre = Convert.ToInt32(Request.QueryString["pageNoPre"]);
            if (pageNoPre == 0)
                pageNoPre = 1;
        }
        catch
        {
            pageNoPre = 1;
        }

        try
        {
            pageNoEnh = Convert.ToInt32(Request.QueryString["pageNoEnh"]);
            if (pageNoEnh == 0)
                pageNoEnh = 1;
        }
        catch
        {
            pageNoEnh = 1;
        }

        try
        {
            pageNoStd = Convert.ToInt32(Request.QueryString["pageNoStd"]);
            if (pageNoStd == 0)
                pageNoStd = 1;
        }
        catch
        {
            pageNoStd = 1;
        }

        try
        {
            pageNoNon = Convert.ToInt32(Request.QueryString["pageNoNon"]);
            if (pageNoNon == 0)
                pageNoNon = 1;
        }
        catch
        {
            pageNoNon = 1;
        }


        if (!Page.IsPostBack)
        {
           // Response.Write(Session["StdDentistId"].ToString());

            // set images for left panel
            if (imgfindoc != null)
            {
                imgfindoc.ImageUrl = Session["strhttp"] + "images/why-join-heading.gif";
                Imgbot.ImageUrl = Session["strhttp"] + "images/cor-bot.gif";
                //  Imgbanner.ImageUrl = Session["strhttp"] + "images/banner01.gif";
            }

            bFeaDocsFound = (Session["sDentistId"] != null && Session["sDentistId"].ToString().Trim() != "");
            bStdFeaDoc = (Session["StdDentistId"] != null && Session["StdDentistId"].ToString().Trim() != "");
            bPreFeaDoc = (Session["PreDentistId"] != null && Session["PreDentistId"].ToString().Trim() != "");
            bEnFeaDoc = (Session["EnDentistId"] != null && Session["EnDentistId"].ToString().Trim() != "");

            if (Session["Travel_Dis"] != null && Session["Travel_Dis"].ToString().Trim() != "")
            {
                TravelDis = Session["Travel_Dis"].ToString();
            }

            if (bFeaDocsFound || bStdFeaDoc || bPreFeaDoc || bEnFeaDoc)
            {
                //string to store all the Dentist id's
                tDentistsId = Session["sDentistId"].ToString();
                StdDentistsId = Session["StdFeaDentistId"].ToString();

                // check the parent page
                try
                {
                    frompage = Session["pageFromOrAction"].ToString();
                }
                catch
                {
                    //frompage = "advanced";  
                }

                BindGrid(FeaturedDentistType.NonFeatured);
                BindGrid(FeaturedDentistType.Standard);
                BindGrid(FeaturedDentistType.Enhanced);
                BindGrid(FeaturedDentistType.Premium);
            }
            else
            {
                Response.Redirect("SearchDentist_adv.aspx");
            }
        }
        else
        {
            BindGrid(FeaturedDentistType.NonFeatured);
            BindGrid(FeaturedDentistType.Standard);
            BindGrid(FeaturedDentistType.Enhanced);
            BindGrid(FeaturedDentistType.Premium);
        }

    }

    /// <summary>
    /// Bind one of the any four Grids as per the Featured Dentist Type
    /// </summary>
    /// <param name="FeatureType"></param>
    /// <author>Akash Saxena</author>
    /// <date>31 Oct 2007</date>
    public void BindGrid(FeaturedDentistType FeatureType)
    {
        string DentistsId = string.Empty;
        DataSet ds; 
        switch (FeatureType)
        {
            case FeaturedDentistType.NonFeatured:
                #region Non Featured Dentists List
                DentistsId = Convert.ToString(Session["sDentistId"]);
                if (DentistsId.Length > 0)
                {
                    //SqlParameter[] ProcParameter = new SqlParameter[4];
                    //ProcParameter[0] = new SqlParameter("@IDs", SqlDbType.VarChar, 8000);
                    //ProcParameter[0].Value = DentistsId;
                    //ProcParameter[1] = new SqlParameter("@State", SqlDbType.VarChar, 2);
                    //ProcParameter[1].Value = string.Empty;
                    //ProcParameter[2] = new SqlParameter("@City", SqlDbType.VarChar, 50);
                    //ProcParameter[2].Value = string.Empty;
                    //ProcParameter[3] = new SqlParameter("@Zip", SqlDbType.VarChar, 10);
                    //ProcParameter[3].Value = string.Empty;

                    ////ProcParameter[4] = new SqlParameter("@Travel_Dis", SqlDbType.BigInt, 10);
                    ////ProcParameter[4].Value = 0;

                    //if (Session["Travel_Dis"].ToString() != "" && Session["Travel_Dis"] != null)
                    //{
                    //    ProcParameter[1].Value = Convert.ToString(Session["State"]);
                    //    ProcParameter[2].Value = Convert.ToString(Session["City"]);
                    //    ProcParameter[3].Value = Convert.ToString(Session["ZipCode"]);
                    //    grdSearch.Columns[4].Visible = true;
                    //}
                    //else
                    //{
                    //    grdSearch.Columns[4].Visible = false;
                    //}
                    //NormalPaging.BindToControl = "grdSearch";
                    //NormalPaging.SqlParameterList = ProcParameter;
                    //NormalPaging.StoredProcedureName = "DentSearch";
                    //NormalPaging.OrderBy = "id";
                    //grdSearch.Visible = true;

                    // NEW CODE 17 JAN 2008
                    ds = mgr.ExecuteQuery(returnSql(GetPageId(pageNoNon, DentistsId, "NonFeatured")), "tbl_drdet");
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        if (Session["Travel_Dis"].ToString() != "" && Session["Travel_Dis"] != null)  // to make distance column visibility true if search criteria includes Distance Search Functionality
                        {
                            ds.Tables[0].DefaultView.Sort = " distance,rating desc";
                            grdSearch.Columns[4].Visible = true;
                        }
                        else
                        {
                            ds.Tables[0].DefaultView.Sort = " rating desc";
                            grdSearch.Columns[4].Visible = false;
                        }

                        grdSearch.DataSource = ds.Tables[0].DefaultView;
                        if (pageNoNon > grdSearch.PageCount)
                            grdSearch.PageIndex = 1;
                        else
                            grdSearch.PageIndex = pageNoNon;
                        grdSearch.DataBind();
                        //lbl_FeaMsg.Text = "Featured Links ";
                        //lbl_FeaMsg.ForeColor = System.Drawing.Color.Navy;
                        //lbl_FeaMsg.Font.Bold = true;
                        //lbl_FeaMsg.Font.Size = 11;
                        //tbl_feat.Visible = true;
                    }
                    else
                    {
                        tbl_feat.Visible = false;
                        lbl_FeaMsg.Text = "No more Featured Links";
                        lbl_FeaMsg.ForeColor = System.Drawing.Color.Red;
                    }
                }

                else
                {
                    grdSearch.Visible = false;
                }
                #endregion
                break;
            case FeaturedDentistType.Standard:
                #region Standard Featured Dentists List
                DentistsId = Convert.ToString(Session["StdDentistId"]);
                if (DentistsId.Length > 0)
                {
                    //SqlParameter[] ProcParameter = new SqlParameter[4];
                    //ProcParameter[0] = new SqlParameter("@IDs", SqlDbType.VarChar, 8000);
                    //ProcParameter[0].Value = DentistsId;
                    //ProcParameter[1] = new SqlParameter("@State", SqlDbType.VarChar, 2);
                    //ProcParameter[1].Value = string.Empty;
                    //ProcParameter[2] = new SqlParameter("@City", SqlDbType.VarChar, 50);
                    //ProcParameter[2].Value = string.Empty;
                    //ProcParameter[3] = new SqlParameter("@Zip", SqlDbType.VarChar, 10);
                    //ProcParameter[3].Value = string.Empty;

                    //if (Session["Travel_Dis"].ToString() != "" && Session["Travel_Dis"] != null)
                    //{
                    //    ProcParameter[1].Value = Convert.ToString(Session["State"]);
                    //    ProcParameter[2].Value = Convert.ToString(Session["City"]);
                    //    ProcParameter[3].Value = Convert.ToString(Session["ZipCode"]);
                    //    //grdPremium.Columns[4].Visible = true;
                    //}
                    //StandardPaging.BindToControl = "StandardFeaDoc";
                    //StandardPaging.SqlParameterList = ProcParameter;
                    //StandardPaging.StoredProcedureName = "DentSearch";
                    //StandardPaging.OrderBy = "id";

                    //StandardFeaDoc.Visible = true;
                    ds = mgr.ExecuteQuery(returnSql(GetPageId(pageNoStd, DentistsId, "Standard")), "tbl_drdet");
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        if (Session["Travel_Dis"].ToString() != "" && Session["Travel_Dis"] != null)  // to make distance column visibility true if search criteria includes Distance Search Functionality
                        {
                            ds.Tables[0].DefaultView.Sort = " distance,rating desc";
                            //   StandardFeaDoc.Columns[4].Visible = true;
                        }
                        else
                        {
                            ds.Tables[0].DefaultView.Sort = " rating desc";
                            //     StandardFeaDoc.Columns[4].Visible = false;
                        }

                        StandardFeaDoc.DataSource = ds.Tables[0].DefaultView;
                        if (pageNoStd > StandardFeaDoc.PageCount)
                            StandardFeaDoc.PageIndex = 1;
                        else
                            StandardFeaDoc.PageIndex = pageNoStd;
                        StandardFeaDoc.DataBind();
                        lbl_FeaMsg.Text = "Featured Links ";
                        lbl_FeaMsg.ForeColor = System.Drawing.Color.Navy;
                        lbl_FeaMsg.Font.Bold = true;
                        lbl_FeaMsg.Font.Size = 11;
                        tbl_feat.Visible = true;
                    }
                    else
                    {
                        tbl_feat.Visible = false;
                        lbl_FeaMsg.Text = "No more Featured Links";
                        lbl_FeaMsg.ForeColor = System.Drawing.Color.Red;
                    }

                }
                else
                {
                    StandardFeaDoc.Visible = false;
                    tbl_feat.Visible = false;
                }

                #endregion
                break;

            case FeaturedDentistType.Enhanced:
                #region Enhanced Featured Dentists List
                DentistsId = Convert.ToString(Session["EnDentistId"]);
                if (DentistsId.Length > 0)
                {
                    //SqlParameter[] ProcParameter = new SqlParameter[4];
                    //ProcParameter[0] = new SqlParameter("@IDs", SqlDbType.Text);
                    //ProcParameter[0].Value = DentistsId;
                    //ProcParameter[1] = new SqlParameter("@State", SqlDbType.VarChar, 2);
                    //ProcParameter[1].Value = string.Empty;
                    //ProcParameter[2] = new SqlParameter("@City", SqlDbType.VarChar, 50);
                    //ProcParameter[2].Value = string.Empty;
                    //ProcParameter[3] = new SqlParameter("@Zip", SqlDbType.VarChar, 10);
                    //ProcParameter[3].Value = string.Empty;

                    //if (Session["Travel_Dis"].ToString() != "" && Session["Travel_Dis"] != null)
                    //{
                    //    ProcParameter[1].Value = Convert.ToString(Session["State"]);
                    //    ProcParameter[2].Value = Convert.ToString(Session["City"]);
                    //    ProcParameter[3].Value = Convert.ToString(Session["ZipCode"]);
                    //    grdEnhanced.Columns[4].Visible = true;
                    //}
                    //else
                    //{
                    //    grdEnhanced.Columns[4].Visible = false;
                    //}

                    //EnhancePaging.BindToControl = "grdEnhanced";
                    //EnhancePaging.SqlParameterList = ProcParameter;
                    //EnhancePaging.StoredProcedureName = "DentSearch";
                    //EnhancePaging.OrderBy = "id";

                    //grdEnhanced.Visible = true;

                    ds = mgr.ExecuteQuery(returnSql(GetPageId(pageNoEnh, DentistsId, "Enhance")), "tbl_drdet");
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        if (Session["Travel_Dis"].ToString() != "" && Session["Travel_Dis"] != null)  // to make distance column visibility true if search criteria includes Distance Search Functionality
                        {
                            ds.Tables[0].DefaultView.Sort = " distance,rating desc";
                            grdEnhanced.Columns[4].Visible = true;
                        }
                        else
                        {
                            ds.Tables[0].DefaultView.Sort = " rating desc";
                            grdEnhanced.Columns[4].Visible = false;
                        }

                        grdEnhanced.DataSource = ds.Tables[0].DefaultView;
                        if (pageNoEnh > grdEnhanced.PageCount)
                            grdEnhanced.PageIndex = 1;
                        else
                            grdEnhanced.PageIndex = pageNoEnh;
                        grdEnhanced.DataBind();
                        lblMsgEnhance.Text = "Featured Links ";
                        lblMsgEnhance.ForeColor = System.Drawing.Color.Navy;
                        lblMsgEnhance.Font.Bold = true;
                        lblMsgEnhance.Font.Size = 11;
                        trEnhance.Visible = true;
                        trEnhanceMsg.Visible = true;
                        trEnhancePaging.Visible = true;
                    }
                    else
                    {
                        tbl_feat.Visible = false;
                        lbl_FeaMsg.Text = "No more Featured Links";
                        lbl_FeaMsg.ForeColor = System.Drawing.Color.Red;
                    }
                }
                else
                {
                    grdEnhanced.Visible = false;
                }
                #endregion
                break;

            case FeaturedDentistType.Premium:
                #region Premium Featured Dentists List
                DentistsId = Convert.ToString(Session["PreDentistId"]);
                if (DentistsId.Length > 0)
                {
                    //SqlParameter[] ProcParameter = new SqlParameter[4];
                    //ProcParameter[0] = new SqlParameter("@IDs", SqlDbType.Text);
                    //ProcParameter[0].Value = DentistsId;
                    //ProcParameter[1] = new SqlParameter("@State", SqlDbType.VarChar, 2);
                    //ProcParameter[1].Value = string.Empty;
                    //ProcParameter[2] = new SqlParameter("@City", SqlDbType.VarChar, 50);
                    //ProcParameter[2].Value = string.Empty;
                    //ProcParameter[3] = new SqlParameter("@Zip", SqlDbType.VarChar, 10);
                    //ProcParameter[3].Value = string.Empty;

                    //if (Session["Travel_Dis"].ToString() != "" && Session["Travel_Dis"] != null)
                    //{
                    //    ProcParameter[1].Value = Convert.ToString(Session["State"]);
                    //    ProcParameter[2].Value = Convert.ToString(Session["City"]);
                    //    ProcParameter[3].Value = Convert.ToString(Session["ZipCode"]);
                    //    grdPremium.Columns[4].Visible = true;
                    //}
                    //else
                    //{
                    //    grdPremium.Columns[4].Visible = false;
                    //}

                    //PremiumPaging.BindToControl = "grdPremium";
                    //PremiumPaging.SqlParameterList = ProcParameter;
                    //PremiumPaging.StoredProcedureName = "DentSearch";
                    //PremiumPaging.OrderBy = "id";

                    //grdPremium.Visible = true;

                    ds = mgr.ExecuteQuery(returnSql(GetPageId(pageNoPre, DentistsId, "Premium")), "tbl_drdet");
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        if (Session["Travel_Dis"].ToString() != "" && Session["Travel_Dis"] != null)  // to make distance column visibility true if search criteria includes Distance Search Functionality
                        {
                            ds.Tables[0].DefaultView.Sort = " distance,rating desc";
                            grdPremium.Columns[4].Visible = true;
                        }
                        else
                        {
                            ds.Tables[0].DefaultView.Sort = " rating desc";
                            grdPremium.Columns[4].Visible = false;
                        }

                        grdPremium.DataSource = ds.Tables[0].DefaultView;
                        if (pageNoPre > grdPremium.PageCount)
                            grdPremium.PageIndex = 1;
                        else
                            grdPremium.PageIndex = pageNoPre;
                        grdPremium.DataBind();
                        lblMsgPremium.Text = "Featured Links ";
                        lblMsgPremium.ForeColor = System.Drawing.Color.Navy;
                        lblMsgPremium.Font.Bold = true;
                        lblMsgPremium.Font.Size = 11;
                        trPremium.Visible = true;
                        trPremiumMsg.Visible = true;
                        trPremiumPaging.Visible = true;
                    }
                    else
                    {
                        tbl_feat.Visible = false;
                        lbl_FeaMsg.Text = "No more Featured Links";
                        lbl_FeaMsg.ForeColor = System.Drawing.Color.Red;
                    }
                }
                else
                {
                    grdPremium.Visible = false;
                }
                #endregion
                break;
        }
        return;
    }


    public string getPhoto(object photo, object sex)
    {
        string p = photo.ToString();
        if (p.Length > 0)
        {
            if (File.Exists(Request.PhysicalApplicationPath + "\\images\\Dnt_images\\" + photo))
            {
                //return "<img height=\"100\" width=\"80\" src='images/Dr_images/" + photo + "'>";
                //string str_path = mgr.getThumbnaleImage("images/Dnt_images/" + photo, 80, 100, false, "");
                string str_path = getThumbnaleImageWithURLFormat(photo.ToString(), 80, 100, false, "", Session["strHTTP"].ToString());
                return str_path;
            }
            else
            {
                if (sex.ToString().ToLower() == "m")
                    return "<img height=\"100\" width=\"80\" src='" + Session["strHttp"].ToString() + "images/Dnt_images/silhouette-male.gif'>";
                else
                    return "<img height=\"100\" width=\"80\" src='" + Session["strHttp"].ToString() + "images/Dnt_images/silhouette--female.gif'>";
            }
        }
        else
        {
            if (sex.ToString().ToLower() == "m")
                return "<img height=\"100\" width=\"80\" src='" + Session["strHttp"].ToString() + "images/Dnt_images/silhouette-male.gif'>";
            else
                return "<img height=\"100\" width=\"80\" src='" + Session["strHttp"].ToString() + "images/Dnt_images/silhouette--female.gif'>";
        }
    }
    protected void btnBackToSearch_Click(object sender, EventArgs e)
    {
        string goToCode = "";
        //if (Request.QueryString["frompage"] != null && Request.QueryString["frompage"].ToString() == "")
        if (Session["pageFromOrAction"] != null && Session["pageFromOrAction"].ToString() != "")
        {
            //string tFrompage = Request.QueryString["frompage"].ToString().Trim();
            goToCode = Session["pageFromOrAction"].ToString();
            switch (goToCode)
            {
                case "home":
                case "simple":
                    Response.Redirect("Default.aspx");
                    break;
                case "connect":
                case "ratePeer":
                    Response.Redirect(Session["strHttps"] + "Dentist/DentistContent.aspx");
                    break;
                case "RateDentists":
                    Response.Redirect(Session["strHttp"] + "patient/patient_rate.aspx?fromPage=RateDentists");
                    break;
                case "drMessage":
                    Response.Redirect(Session["strHttp"] + "boardsblogs/blogs.aspx");
                    break;
                case "advanced":
                    Response.Redirect(Session["strHttp"] + "SearchDentist_adv.aspx");
                    break;
                default:
                    Response.Redirect(Session["strHttp"] + "SearchDentist_adv.aspx");
                    break;
            }
        }
        else
            Response.Redirect(Session["strHttp"] + "SearchDentist_adv.aspx");
    }
    public string getThumbnaleImageWithURLFormat(string imgName, int maxWidth, int maxHeight, bool saveImage, string savePath, string baseURL)
    {
        string s;
        double imgHeight, imgWidth;
        //Response.Write(imgName) ;
        s = Server.MapPath("~/images/Dnt_images/" + imgName);
        //Response.Write("</br>"+s);
        System.Drawing.Image currentImage = System.Drawing.Image.FromFile(s);
        imgHeight = currentImage.Height;
        imgWidth = currentImage.Width;
        if (imgWidth > maxWidth | imgHeight > maxHeight)
        {
            double deltaWidth = imgWidth - maxWidth;
            double deltaHeight = imgHeight - maxHeight;
            double scaleFactor;
            if (deltaHeight > deltaWidth)
                scaleFactor = maxHeight / imgHeight;
            else
                scaleFactor = maxWidth / imgWidth;
            imgWidth *= scaleFactor;
            imgHeight *= scaleFactor;
        }

        if (saveImage)
        {
            if (savePath == "")
                throw new Exception("must pass a file name");
            currentImage.GetThumbnailImage(Convert.ToInt32(imgWidth), Convert.ToInt32(imgHeight), null, IntPtr.Zero).Save(Server.MapPath(savePath));
            currentImage.Dispose();
        }
        //return currentImage.GetThumbnailImage(Convert.ToInt32(imgWidth), Convert.ToInt32(imgHeight), null, IntPtr.Zero);


        return ("<img src=\"" + baseURL + "images/Dnt_images/" + imgName + "\"" + " height=\"" + imgHeight + "\" width=\"" + imgWidth + "\" border='0' alt=''/>");
    }

    #region Paging methods
    // 
    string GetPageId(int pageNo, string id, string docType)
    {
        string did = id; // Session["sDentistId"].ToString();

        int StartIndex = getcPostion(pageNo, id);
        int lastIndex = getcPostion(pageNo + 1, id);
        int totalRecs = GetRecCount(did);

        string ids = did.Substring(StartIndex, lastIndex - StartIndex);
        ids = ids.TrimEnd(',').TrimStart(',');
        int startingRec = 10 * (pageNo - 1) + 1;
        int endingRec = startingRec + (GetRecCount(ids) - 1);

        //switch (docType)
        //{
        //    case "Premium":
        //        litPaging.Text = "<table border='0' width='100%'><tr><td>Displaying " + startingRec + " to " + endingRec + " of " + totalRecs + "</td><td align='right'>";
        //        if (pageNo > 1)
        //            litPaging.Text += "<a href='SearchResultsDent.aspx?pageNoPre=" + (pageNo - 1) + "&" + Request.QueryString.ToString() + "'>Previous</a>";
        //        if (pageNo < (totalRecs / 10) || (pageNo == (totalRecs / 10) && (totalRecs % 10) != 0))
        //            litPaging.Text += "&nbsp;&nbsp;&nbsp;<a href='SearchResultsDent.aspx?pageNoPre=" + (pageNo + 1) + "&" + Request.QueryString.ToString() + "'>Next</a>";
        //        litPaging.Text += "</td></tr></table>";
        //        break;
        //    case "Enhance":
        //        enhance.Text = "<table border='0' width='100%'><tr><td>Displaying " + startingRec + " to " + endingRec + " of " + totalRecs + "</td><td align='right'>";
        //        if (pageNo > 1)
        //            enhance.Text += "<a href='SearchResultsDent.aspx?pageNoEnh=" + (pageNo - 1) + "&" + Request.QueryString.ToString() + "'>Previous</a>";
        //        if (pageNo < (totalRecs / 10) || (pageNo == (totalRecs / 10) && (totalRecs % 10) != 0))
        //            enhance.Text += "&nbsp;&nbsp;&nbsp;<a href='SearchResultsDent.aspx?pageNoEnh=" + (pageNo + 1) + "&" + Request.QueryString.ToString() + "'>Next</a>";
        //        enhance.Text += "</td></tr></table>";
        //    //enhance.Text = "<table border='1'><tr><td>Displaying " + startingRec + " to " + endingRec + " of " + totalRecs + "</td><td align='right'>";
        //        //if (pageNo > 1)
        //        //    enhance.Text += "<a href='SearchResultsDent.aspx?pageNoEnh=" + (pageNo - 1) + "'>Previous</a>";
        //        //if (pageNo < (totalRecs / 10) || (pageNo == (totalRecs / 10) && (totalRecs % 10) != 0))
        //        //    enhance.Text += "&nbsp;&nbsp;&nbsp;<a href='SearchResultsDent.aspx?pageNoEnh=" + (pageNo + 1) + "'>Next</a>";
        //        //litPaging.Text += "</td></tr></table>";
        //        break;
        //    case "Standard":
        //        Standard.Text = "<table border='0' width='100%'><tr><td>Displaying " + startingRec + " to " + endingRec + " of " + totalRecs + "</td><td align='right'>";
        //        if (pageNo > 1)
        //            Standard.Text += "<a href='SearchResultsDent.aspx?pageNoStd=" + (pageNo - 1) + "&" + Request.QueryString.ToString() + "'>Previous</a>";
        //        if (pageNo < (totalRecs / 10) || (pageNo == (totalRecs / 10) && (totalRecs % 10) != 0))
        //            Standard.Text += "&nbsp;&nbsp;&nbsp;<a href='SearchResultsDent.aspx?pageNoStd=" + (pageNo + 1) + "&" + Request.QueryString.ToString() + "'>Next</a>";
        //        Standard.Text += "</td></tr></table>";
        //        break;
        //    case "NonFeatured":
        //        Normal.Text = "<table border='0' width='100%'><tr><td>Displaying " + startingRec + " to " + endingRec + " of " + totalRecs + "</td><td align='right'>";
        //        if (pageNo > 1)
        //            Normal.Text += "<a href='SearchResultsDent.aspx?pageNoNon=" + (pageNo - 1) + "&" + Request.QueryString.ToString() + "'>Previous</a>";
        //        if (pageNo < (totalRecs / 10) || (pageNo == (totalRecs / 10) && (totalRecs % 10) != 0))
        //            Normal.Text += "&nbsp;&nbsp;&nbsp;<a href='SearchResultsDent.aspx?pageNoNon=" + (pageNo + 1) + "&" + Request.QueryString.ToString() + "'>Next</a>";
        //        Normal.Text += "</td></tr></table>";
        //        break;
        //}

        switch (docType)
        {
            case "Premium":
                litPaging.Text = "<table width='100%'><tr><td>Displaying " + startingRec + " to " + endingRec + " of " + totalRecs + "</td><td align='right'>";
                if (pageNo > 1)
                {
                    object page = pageNo - 1;
                    litPaging.Text += "<a href='" + UpdateQueryStringItem(Page.Request, "pageNoPre", page.ToString()) + "'>Previous</a>";
                    //  litPaging.Text += "<a href='SearchResultsDocs.aspx?pageNoPre=" + (pageNo - 1) + "&" + Request.QueryString.ToString() + "'>Previous</a>";
                }
                if (pageNo < (totalRecs / 10) || (pageNo == (totalRecs / 10) && (totalRecs % 10) != 0))
                {
                    //litPaging.Text += "&nbsp;&nbsp;&nbsp;<a href='SearchResultsDocs.aspx?pageNoPre=" + (pageNo + 1) + "&" + Request.QueryString.ToString() + "'>Next</a>";
                    object page = pageNo + 1;
                    litPaging.Text += "&nbsp;&nbsp;&nbsp;<a href='" + UpdateQueryStringItem(Page.Request, "pageNoPre", page.ToString()) + "'>Next</a>";
                }

                litPaging.Text += "</td></tr></table>";

                break;
            case "Enhance":
                enhance.Text = "<table width='100%'><tr><td>Displaying " + startingRec + " to " + endingRec + " of " + totalRecs + "</td><td align='right'>";
                if (pageNo > 1)
                {
                    object page = pageNo - 1;
                    enhance.Text += "<a href='" + UpdateQueryStringItem(Page.Request, "pageNoEnh", page.ToString()) + "'>Previous</a>";
                    // enhance.Text += "<a href='SearchResultsDocs.aspx?pageNoEnh=" + (pageNo - 1) + "&" + Request.QueryString.ToString() + "'>Previous</a>";
                }
                if (pageNo < (totalRecs / 10) || (pageNo == (totalRecs / 10) && (totalRecs % 10) != 0))
                {
                    object page = pageNo + 1;
                    enhance.Text += "&nbsp;&nbsp;&nbsp;<a href='" + UpdateQueryStringItem(Page.Request, "pageNoEnh", page.ToString()) + "'>Next</a>";
                    // enhance.Text += "&nbsp;&nbsp;&nbsp;<a href='SearchResultsDocs.aspx?pageNoEnh=" + (pageNo + 1) + "&" + Request.QueryString.ToString() + "'>Next</a>";
                }
                enhance.Text += "</td></tr></table>";
                //enhance.Text = "<table width='100%'><tr><td>Displaying " + startingRec + " to " + endingRec + " of " + totalRecs + "</td><td align='right'>";
                //if (pageNo > 1)
                //    enhance.Text += "<a href='SearchResultsDocs.aspx?pageNoEnh=" + (pageNo - 1) + "'>Previous</a>";
                //if (pageNo < (totalRecs / 10) || (pageNo == (totalRecs / 10) && (totalRecs % 10) != 0))
                //    enhance.Text += "&nbsp;&nbsp;&nbsp;<a href='SearchResultsDocs.aspx?pageNoEnh=" + (pageNo + 1) + "'>Next</a>";
                //litPaging.Text += "</td></tr></table>";
                break;
            case "Standard":
                Standard.Text = "<table width='100%'><tr><td>Displaying " + startingRec + " to " + endingRec + " of " + totalRecs + "</td><td align='right'>";
                if (pageNo > 1)
                {
                    object page = pageNo - 1;
                    Standard.Text += "<a href='" + UpdateQueryStringItem(Page.Request, "pageNoStd", page.ToString()) + "'>Previous</a>";
                    //  Standard.Text += "<a href='SearchResultsDocs.aspx?pageNoStd=" + (pageNo - 1) + "&" + Request.QueryString.ToString() + "'>Previous</a>";
                }
                if (pageNo < (totalRecs / 10) || (pageNo == (totalRecs / 10) && (totalRecs % 10) != 0))
                {
                    object page = pageNo + 1;
                    Standard.Text += "&nbsp;&nbsp;&nbsp;<a href='" + UpdateQueryStringItem(Page.Request, "pageNoStd", page.ToString()) + "'>Next</a>";
                    //   Standard.Text += "&nbsp;&nbsp;&nbsp;<a href='SearchResultsDocs.aspx?pageNoStd=" + (pageNo + 1) + "&" + Request.QueryString.ToString() + "'>Next</a>";
                }
                Standard.Text += "</td></tr></table>";
                break;
            case "NonFeatured":
                Normal.Text = "<table width='100%'><tr><td>Displaying " + startingRec + " to " + endingRec + " of " + totalRecs + "</td><td align='right'>";
                if (pageNo > 1)
                {
                    object page = pageNo - 1;
                    Normal.Text += "<a href='" + UpdateQueryStringItem(Page.Request, "pageNoNon", page.ToString()) + "'>Previous</a>";
                    //   Normal.Text += "<a href='SearchResultsDocs.aspx?pageNoNon=" + (pageNo - 1) + "&" + Request.QueryString.ToString() + "'>Previous</a>";
                }
                if (pageNo < (totalRecs / 10) || (pageNo == (totalRecs / 10) && (totalRecs % 10) != 0))
                {
                    object page = pageNo + 1;
                    Normal.Text += "&nbsp;&nbsp;&nbsp;<a href='" + UpdateQueryStringItem(Page.Request, "pageNoNon", page.ToString()) + "'>Next</a>";
                    //   Normal.Text += "&nbsp;&nbsp;&nbsp;<a href='SearchResultsDocs.aspx?pageNoNon=" + (pageNo + 1) + "&" + Request.QueryString.ToString() + "'>Next</a>";
                }
                Normal.Text += "</td></tr></table>";
                break;
        }

        //     litPagingBelow.Text = litPaging.Text;
        return ids;
    }

    int getcPostion(int pageNo, string id)
    {
        string did = id; // Session["sDentistId"].ToString();
        int startNo = (pageNo - 1) * 10;
        int pos = 0;
        int pr = 0;
        //   Response.Write("startNo: " + startNo + "<BR>");
        for (int i = 0; i < startNo; i++)
        {
            pos = did.IndexOf(',', pr);
            //     Response.Write("<BR>Pos: " + pos);
            pr = pos + 1;
            if (did.IndexOf(',', pr) == -1)
            {
                pos = did.Length;
                break;
            }
        }
        return pos;
    }

    private int GetRecCount(string csvStr)
    {
        return csvStr.Split(new char[] { ',' }).Length;
    }

    #region Query
    /// <summary>
    /// Inline query has been wirtten because long id string cannot be pass to stored procedure
    /// </summary>
    /// <param name="ids"></param>
    /// <returns></returns>
    string returnSql(string ids)
    {
        //Response.Write(ids);
        Manager mgr = new Manager(true,"ConnectionString");
        string strSql = @"SELECT QU FROM DENTIST_FUNC_RATING()";

        SqlDataReader dr = mgr.ExecuteQuery(strSql);
        System.String orderClause = "";
        System.String AttachMiles = "";
        if (Session["Travel_Dis"].ToString() != "" && Session["Travel_Dis"].ToString() != null) //  to order the result first by Distance and then by rating Desc / to Calculate Miles
        {
            orderClause = "order by Distance ASC, Rating Desc";
            AttachMiles = " , (dbo.GetDistanceInMiles('" + Session["ZipCode"].ToString() + "','" + Session["City"].ToString() + "','" + Session["State"].ToString() + "',zipcodesearch)) as Distance";

        }
        else
        {
            orderClause = "order by Rating Desc";
            AttachMiles = ",'' as distance";
        }

        if (dr.Read())
        {
            strSql = @"select d.city, d.zipcode, sp.specialty as specialityName,
            (select tbl_DentistSubSpecialty.specialty from tbl_DentistSubSpecialty where
			 tbl_DentistSubSpecialty.specialty not in(Sp.specialty) and
			 tbl_DentistSubSpecialty.id=d.secondaryspecialityid)
             as SubSpec,
             rtrim((select name from tbl_states where stateId = d.state)) as state,
            CAST((" + dr[0].ToString() + @") as numeric(8,2)) as rating,d.id as id,fname + ' ' + mname + ' ' + lname as docname, address1 + '<br>' + city + ', ' + state as address,
             Sp.specialty + isnull(', ' + (select tbl_DentistSubSpecialty.specialty from tbl_DentistSubSpecialty where
			tbl_DentistSubSpecialty.specialty not in(Sp.specialty) and
			 tbl_DentistSubSpecialty.id=d.secondaryspecialityid),'') as speciality,
            isnull(dp.website,'')as website,isnull(dp.photo,'') as photo,d.gender" + AttachMiles +
            " from tbl_Dentists d "
//            + " left outer join tbl_secondaryspeciality s on s.id=d.secondaryspecialityid "
            + " left outer join tbl_DentistSubSpecialty s on s.id=d.secondaryspecialityid "
            + " left outer join tbl_dntpremium dp on dp.dnt_id=d.id "
            + " left outer join tbl_dentistspecialty sp on sp.id=D.specialityid "
             + " where  d.isdelete=0 and d.id in (" + ids + ") " + orderClause;


            //            Response.Write(strSql);

            //a.d. code, will be implemented, if required

            //(dbo.GetDistanceInMiles('" + Session["Travel_Dis"].ToString() + "','" + Session["City"].ToString() 
            //+ @"',substring(d.ZipCode,1,5))) as Distance

        }

        return strSql;
    }
    #endregion

    #endregion
}
